<?php
$this->breadcrumbs = array(
    'Sites' => array('index'),
    'Manage',
);

$this->menu = array(
    array('label' => 'Create Site', 'url' => array('create')),
);

$script = "
\$('.grid-view .status-column a').live('click', function(){
    if (\$(this).parent().hasClass('default'))
        return false;
    $.get(\$(this).attr('href'), function(){
        $('.grid-view .filters input').trigger('change');
    });
    return false;
});
";
Yii::app()->clientScript->registerScript(__CLASS__ . '#ChangeStatus', $script, CClientScript::POS_READY);
$script = "
\$('.grid-view .status-column.default a.active').live('click', function(){return false;});
";
Yii::app()->clientScript->registerScript(__CLASS__ . '#DisableStatus', $script, CClientScript::POS_READY);
?>

<h1>Manage Sites</h1>

<!--<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>-->

<?php //echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
    <?php $this->renderPartial('_search', array(
    'model' => $model,
)); ?>
</div><!-- search-form -->

<?php $grid = $this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'site-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'selectableRows' => 2,
    'selectionChanged' => "updateSelectors",
    'columns' => array(
        array(
            'class' => 'CCheckBoxColumn',
            'value' => '$data->id',
            'htmlOptions' => array('width' => '3%'),
        ),
        array(
            'name' => 'name',
            'type' => 'raw',
            'value' => 'CHtml::link($data->name, array("update", "id"=>$data->id))',
        ),
        /* array(
            'class'=>'CLinkColumn',
            'header'=>'Language',
            //'url'=>,
            'label'=>'Manager language',
            'urlExpression'=>'Yii::app()->controller->createUrl("/Admin/Language/admin",array("Language[site_id]"=>$data->id))',
            'htmlOptions'=>array('width'=>'10%'),
        ),*/
        array(
            'name' => 'status',
            'type' => 'raw',
            'value' => 'CHtml::link($data->statusText, array("status", "ids[]"=>$data->id, "value"=>$data->status ? 0 : 1), array("class"=>($data->status ? "active" : "")))',
            'filter' => false,
            'cssClassExpression' => '$data->default ? "default" : ""',
            'htmlOptions' => array(
                'class' => 'status-column'
            )
        ),
        array(
            'name' => 'default',
            'type' => 'raw',
            'value' => 'CHtml::link("Set default", "#", array("class"=>($data->default ? "default" : "")))',
            'filter' => false,
            'htmlOptions' => array(
                'class' => 'set-default-column'
            )
        ),
        array(
            'name' => 'creation_datetime',
            'value' => 'Yii::app()->getDateFormatter()->formatDateTime(strtotime($data->creation_datetime))',
            'filter' => false,
            'htmlOptions' => array(
                'class' => 'datetime-column'
            )
        ),
        array(
            'name' => 'last_update',
            'value' => 'Yii::app()->getDateFormatter()->formatDateTime(strtotime($data->last_update))',
            'filter' => false,
            'htmlOptions' => array(
                'class' => 'datetime-column'
            )
        ),
        array(
            'name' => 'id',
            'value' => '$data->id',
            'filter' => false,
            'visible' => false,
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => '{update} {delete} {language}',
            'buttons' => array(
                'update', 'delete',
                'language' => array(
                    'label' => 'Language', // text label of the button
                    'url' => 'Yii::app()->controller->createUrl("/Admin/language/admin",array("siteId"=>$data->id))', // a PHP expression for generating the URL of the button
                    'imageUrl' => themeUrl() . '/images/global.png',
                ),
            ),
            'cssClassExpression' => '$data->default ? "default" : ""',
        ),
    ),
));

if ($grid->dataProvider->ItemCount) {
    $this->menu[] = array('label' => 'Delete selected items', 'url' => $this->createUrl('delete'), 'linkOptions' => array('onclick' => 'return multipleDelete("site-grid",this.href)'));
}
Yii::app()->clientScript->registerScriptFile(Yii::app()->core->AssetUrl . '/scripts/gridview.js', CClientScript::POS_BEGIN);
?>